package com.huidu.bitrade.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huidu.bitrade.dto.AcAwardExportDto;
import com.huidu.bitrade.mapper.AcReferrerRewardsMapper;
import com.huidu.bitrade.vo.AcReferrerRewardsVO;
import com.huidu.bitrade.vo.export.*;
import com.huidu.bitrade.vo.export.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class MemberAwardService {

    private final AcReferrerRewardsMapper acReferrerRewardsMapper;

    /**
     * 升星奖励导出
     * @param page 分页
     * @param list
     * @return
     */
    public List<AcReferrerRewardsExport> memberStarRecordExport(AcAwardExportDto exportParam, IPage page, List<AcReferrerRewardsExport> list){
        IPage<AcReferrerRewardsExport> rewardsExportIPage = page.setRecords(acReferrerRewardsMapper.memberStarRecordExport(page,exportParam));
        long totalPage = rewardsExportIPage.getPages();
        if (page.getCurrent() <= totalPage) {
            list.addAll(rewardsExportIPage.getRecords());
            page.setCurrent(page.getCurrent()+1);
            return memberStarRecordExport(exportParam, page, list);
        }
        return list;
    }
    /**
     * HDC奖励导出
     * @param page 分页
     * @param list
     * @return
     */
    public List<AcHdcAwardExport> hdcAwardExport(AcAwardExportDto exportParam, IPage page, List<AcHdcAwardExport> list){
        IPage<AcHdcAwardExport> rewardsExportIPage = page.setRecords(acReferrerRewardsMapper.hdcAwardExport(page,exportParam));
        long totalPage = rewardsExportIPage.getPages();
        if (page.getCurrent() <= totalPage) {
            list.addAll(rewardsExportIPage.getRecords());
            page.setCurrent(page.getCurrent()+1);
            return hdcAwardExport(exportParam, page, list);
        }
        return list;
    }
    /**
     * 购买记录导出
     * @param page 分页
     * @param list
     * @return
     */
    public List<AcMemberExport> memberRecordExport(AcAwardExportDto exportParam, IPage page, List<AcMemberExport> list){
        IPage<AcMemberExport> rewardsExportIPage = page.setRecords(acReferrerRewardsMapper.memberRecordExport(page,exportParam));
        long totalPage = rewardsExportIPage.getPages();
        if (page.getCurrent() <= totalPage) {
            list.addAll(rewardsExportIPage.getRecords());
            page.setCurrent(page.getCurrent()+1);
            return memberRecordExport(exportParam, page, list);
        }
        return list;
    }
    /**
     * 信息查询
     * @param page 分页
     * @param list
     * @return
     */
    public List<AcReferrerRewardsVO> memberInfoExport(AcAwardExportDto exportParam, IPage page, List<AcReferrerRewardsVO> list){
        IPage<AcReferrerRewardsVO> rewardsExportIPage = page.setRecords(acReferrerRewardsMapper.memberInfoExport(page,exportParam));
        long totalPage = rewardsExportIPage.getPages();
        if (page.getCurrent() <= totalPage) {
            list.addAll(rewardsExportIPage.getRecords());
            page.setCurrent(page.getCurrent()+1);
            return memberInfoExport(exportParam, page, list);
        }
        return list;
    }

    /**
     * 手续费奖励
     * @param page 分页
     * @param list
     * @return
     */
    public List<AcChargeHdcAwardExport> chargeAwardRecordExport(AcAwardExportDto exportParam, IPage page, List<AcChargeHdcAwardExport> list){
        IPage<AcChargeHdcAwardExport> rewardsExportIPage = page.setRecords(acReferrerRewardsMapper.chargeAwardRecordExport(page,exportParam));
        long totalPage = rewardsExportIPage.getPages();
        if (page.getCurrent() <= totalPage) {
            list.addAll(rewardsExportIPage.getRecords());
            page.setCurrent(page.getCurrent()+1);
            return chargeAwardRecordExport(exportParam, page, list);
        }
        return list;
    }

    /**
     * 团队手续费奖励
     * @param page 分页
     * @param list
     * @return
     */
    public List<AcGroupChargeAwardExport> groupChargeAwardExport(AcAwardExportDto exportParam, IPage page, List<AcGroupChargeAwardExport> list){
        IPage<AcGroupChargeAwardExport> rewardsExportIPage = page.setRecords(acReferrerRewardsMapper.groupChargeAwardExport(page,exportParam));
        long totalPage = rewardsExportIPage.getPages();
        if (page.getCurrent() <= totalPage) {
            list.addAll(rewardsExportIPage.getRecords());
            page.setCurrent(page.getCurrent()+1);
            return groupChargeAwardExport(exportParam, page, list);
        }
        return list;
    }

}
